package service.impl;

import dao.UserDao;
import pojo.User;
import service.UserService;

import java.sql.SQLException;
import java.util.List;
/**
 * 用户的业务层，依赖持久层（dao）
 */
public class UserServiceImpl implements UserService {
    //dao层接口的实现类，可以注入对象，set方法注入
        private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public int insertUser(User user) {
        int row= 0;
        try {
            row = userDao.insertUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return row;
    }

    /**
     * 查询全表数据
     * 调用持久层方法，返回集合
     */
    @Override
    public List<User> queryUser() {
        List<User> userList = null;
        try {
            userList = userDao.queryUser();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return userList;
    }
}
